{{include_file name='public/header' title='用户管理'}}

</head>

<body>

<div id="wrapper">

    <!-- Navigation -->
    {{include_file name='public/nav' sidebar='sidebar'}}
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">用户管理</h1>

                <div class="search">
                    <div class="well">
                    <form class="form-inline" action="{{url()}}" method="get">
                        <div class="form-group">
                            <label>昵称/账号</label>
                            <input type="text" name="search[name]" class="form-control" placeholder="支持模糊查询" value="{{$search.name}}">
                        </div>
                        <div class="form-group">
                            <label>注册设备</label>
                            <select class="form-control" name="search[device]">
                                {{$devices = \app\user::get_device_list('title')}}
                                <option value="">不限</option>
                                {{foreach $devices as $k => $device}}
                                <option value="{{$k}}" {{if $k == $search.device}}selected{{/if}}>{{$device}}</option>
                                {{/foreach}}
                            </select>
                        </div>
                        <button type="submit" class="btn btn-primary">搜索</button>
                    </form>
                </div>

                </div>

            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">

                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>用户昵称</th>
                                    <th>登录账号</th>
                                    <th>注册渠道</th>
                                    <th>创建项目</th>
                                    <th>参与项目</th>
                                    <th>注册地点</th>
                                    <th>状态</th>
                                    <th>注册时间</th>

                                    <th>操作面板</th>
                                </tr>
                                </thead>
                                <tbody>

                                {{foreach $users as $user}}
                                {{$user_id = $user.id}}
                                {{$device  = $user.device}}
                                <tr>
                                    <td >{{$user.name}}</td>
                                    <td >{{$user.email}}</td>
                                    <td >{{\app\user::get_device_list('icon', $device)}}</td>
                                    <td ><a href="{{url("admin/project/index")}}?creater_id={{$user_id}}" data-toggle="tooltip" title="点击查看具体创建项目">{{\app\user::get_create_project_num($user_id)}}</a></td>
                                    <td ><a href="{{url("admin/project/index")}}?joiner_id={{$user_id}}" data-toggle="tooltip" title="点击查看具体参与项目">{{\app\user::get_join_project_num($user_id)}}</a></td>
                                    <td >{{$user.address}}</td>
                                    <td >
                                        {{if $user.status}}
                                        <i class="fa fa-check"></i>
                                        {{else}}
                                        <i class="fa fa-times"></i>
                                        {{/if}}
                                    </td>

                                    <td >{{$user.add_time}}</td>
                                    <td style="width: 18%;">
                                        {{if $user.status}}
                                        <a type="button" class="btn btn-danger btn-xs js_changeStatusBtn" data-id="{{$user_id}}" data-option="冻结" {{if $user.type == 2}}disabled{{/if}}>冻结用户</a>
                                        {{else}}
                                        <a type="button" class="btn btn-success btn-xs js_changeStatusBtn" data-id="{{$user_id}}" data-option="激活" {{if $user.type == 2}}disabled{{/if}}>激活用户</a>
                                        {{/if}}
                                        <a type="button" class="btn btn-warning btn-xs js_resetPasswordBtn" data-id="{{$user_id}}">重置密码</a>

                                    </td>
                                </tr>
                                {{/foreach}}
                                
                                </tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <div class="col-sm-12">
                {{include_file name='public/page'}}
            </div>

            <!-- /.col-lg-6 -->
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->
    <hr>
    <p class="text-center">{{get_config('copyright')}}</p>
    <script>
        //更改用户状态
        $(".js_changeStatusBtn").click(function(event){

            var userId = $(this).data('id');
            var option = $(this).data('option');

            var url = "{{url('admin/user/change_status')}}";

            confirm('您确认要'+option+'该用户？', function(){

                $.post(url, { user_id:userId }, function(json){

                    alert(json.msg, 1000, function () {
                        window.location.reload();
                    });

                }, 'json');
            });

        });

        //重置密码
        $(".js_resetPasswordBtn").click(function(){

            var userId = $(this).data('id');

            var url = "{{url('admin/user/reset_password')}}";

            var defaultPassword = "{{$default_password}}";

            confirm('您确认要将登录密码重置为'+defaultPassword+'?<br>(系统设置里可以修改重置默认密码)', function(){

                $.post(url, { user_id:userId }, function(json){

                    if(json.code == 200){

                        alert(json.msg, 500);

                    }else{

                        alert(json.msg, 2000);

                    }

                }, 'json');
            });

        });
    </script>

    {{include_file name='public/footer'}}
